package com.dingding.service.mall.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dao.impl.BaseDaoImpl;
import com.dingding.common.core.beans.BannerImage;
import com.dingding.facade.mall.dto.BannerScrollImg;
import com.dingding.service.mall.dao.IBannerImageDao;

/**
 * @Description:积分商城banner图片
 * @author fengshuonan
 * @date 2016年3月23日 下午4:26:13
 */
@Component("bannerImageDao")
public class BannerImageDaoImpl extends BaseDaoImpl<BannerImage> implements IBannerImageDao {

	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * @Description: 获取商城主页的banner的列表
	 * @author fengshuonan
	 * @return List<BannerScrollImg>
	 */
	public List<BannerScrollImg> getBannerImageList(int bannerType, int status) {

		List<BannerImage> banners = null;

		// 创建查询条件
		Criterion criterion = Restrictions.and(Restrictions.eq("bannerShowType", bannerType), // 显示类型：1：商城
																								// 2：app主页显示
				Restrictions.eq("bannerStatus", status));// 显示状态 1:上架 2:下架
		try {
			banners = super.queryCriteriaListByOrder(criterion, Order.asc("showSort"));
		} catch (Exception e) {
			log.error("获取商城主页的banner的列表出错！BannerImageDaoImpl：getMallIndexBannerList", e);
		}

		if (banners != null && banners.size() > 0) {
			List<BannerScrollImg> list = new ArrayList<BannerScrollImg>();
			for (BannerImage bi : banners) {
				BannerScrollImg temp = new BannerScrollImg();
				temp.setBannerContent(bi.getBannerContent());
				temp.setBannerImageName(bi.getBannerImageName());
				list.add(temp);
			}

			return list;
		}
		return null;
	}

}
